### Conscientiousness
#names(wvs_sub)
conscientiousness <- mapply(as.numeric,with(wvs_sub,data.frame(con1, con2, con3, con4, con5, con6, con7, con8, con9, con10)))

conscientiousnesslist <- list()
a <- 0
for(i in 1:9){
  a <- a+(ncol(combn(1:10, i)))
}

b <- 0
items <- list()
for(j in 1:9){
  b=b+1 
  combos <- combn(1:10, j)
  for(i in 1:ncol(combos)){
    items[[b]] <- combos
  }}

itemrow <- lapply(items,nrow)
itemcol <- lapply(items,ncol)

collapsepastecolumns <- function(x)apply(x,2,paste,collapse=",")
rr <- lapply(collapsepastecolumns,X = items)

numbero <-   unlist(itemcol)
emptylist <- list()  
for(i in 2:9){
  emptylist[[i-1]] <- rep(i,numbero[[i-1]])
}

h=1
j=2
i=1
alphacoefs <- data.frame(matrix(nrow=1012,ncol=4))

for(j in 2:9){
  combos <- combn(1:10, j)
  two <- matrix(nrow=nrow(wvs_sub),ncol=ncol(combos))
  for(i in 1:ncol(combos)){
    two[,i] <-   rowMeans(conscientiousness[,combos[,i]])
    alphacoefs[h,] <- psych::alpha(conscientiousness[,combos[,i]],check.keys = TRUE)$total[1:4]
    h=  h+1
  }
  lmcoefs <- matrix(nrow=ncol(combos),ncol=3)
  for(i in 1:ncol(two)){
    lmcoefs[i,1]   <-   lm(zero1(wvs_sub$wvs_lrplacement)~zero1(two[,i])+wvs_sub$IPIP_open+wvs_sub$IPIP_ext+wvs_sub$IPIP_agre+wvs_sub$IPIP_neu+wvs_sub$gender+ wvs_sub$age+ wvs_sub $age2+  wvs_sub$edu2+ wvs_sub$edu3+ wvs_sub$edu4+ wvs_sub$edu5+ wvs_sub$edu6+ wvs_sub$income2+ wvs_sub$income3+ wvs_sub$income4+ wvs_sub$income5+ wvs_sub$income6+ wvs_sub$income7)$coefficients[2]
    lmcoefs[i,2]   <-   lm(zero1(wvs_sub$wvs_moral)~zero1(two[,i])+wvs_sub$IPIP_open+wvs_sub$IPIP_ext+wvs_sub$IPIP_agre+wvs_sub$IPIP_neu+wvs_sub$gender+ wvs_sub$age+ wvs_sub $age2+  wvs_sub$edu2+ wvs_sub$edu3+ wvs_sub$edu4+ wvs_sub$edu5+ wvs_sub$edu6+ wvs_sub$income2+ wvs_sub$income3+ wvs_sub$income4+ wvs_sub$income5+ wvs_sub$income6+ wvs_sub$income7)$coefficients[2]
    lmcoefs[i,3]   <-   lm(zero1(wvs_sub$wvs_economicattitudes)~zero1(two[,i])+wvs_sub$IPIP_open+wvs_sub$IPIP_ext+wvs_sub$IPIP_agre+wvs_sub$IPIP_neu+wvs_sub$gender+ wvs_sub$age+ wvs_sub$age2+  wvs_sub$edu2+ wvs_sub$edu3+ wvs_sub$edu4+ wvs_sub$edu5+ wvs_sub$edu6+ wvs_sub$income2+ wvs_sub$income3+ wvs_sub$income4+ wvs_sub$income5+ wvs_sub$income6+ wvs_sub$income7)$coefficients[2]
  }
  conscientiousnesslist[[j]] <- lmcoefs
  
}
lmcoefs <- matrix(ncol=3)
## 10 item 
lmcoefs[1]   <-   lm(zero1(wvs_sub$wvs_lrplacement)~zero1(rowMeans(conscientiousness))+wvs_sub$IPIP_open+wvs_sub$IPIP_ext+wvs_sub$IPIP_agre+wvs_sub$IPIP_neu+wvs_sub$gender+ wvs_sub$age+ wvs_sub $age2+  wvs_sub$edu2+ wvs_sub$edu3+ wvs_sub$edu4+ wvs_sub$edu5+ wvs_sub$edu6+ wvs_sub$income2+ wvs_sub$income3+ wvs_sub$income4+ wvs_sub$income5+ wvs_sub$income6+ wvs_sub$income7)$coefficients[2]
lmcoefs[2]   <-   lm(zero1(wvs_sub$wvs_moral)~zero1(rowMeans(conscientiousness))+  wvs_sub$IPIP_open+wvs_sub$IPIP_ext+wvs_sub$IPIP_agre+wvs_sub$IPIP_neu+wvs_sub$gender+ wvs_sub$age+ wvs_sub $age2+  wvs_sub$edu2+ wvs_sub$edu3+ wvs_sub$edu4+ wvs_sub$edu5+ wvs_sub$edu6+ wvs_sub$income2+ wvs_sub$income3+ wvs_sub$income4+ wvs_sub$income5+ wvs_sub$income6+ wvs_sub$income7)$coefficients[2]
lmcoefs[3]   <-   lm(zero1(wvs_sub$wvs_economicattitudes)~zero1(rowMeans(conscientiousness))+  wvs_sub$IPIP_open+wvs_sub$IPIP_ext+wvs_sub$IPIP_agre+wvs_sub$IPIP_neu+wvs_sub$gender+ wvs_sub$age+ wvs_sub$age2+  wvs_sub$edu2+ wvs_sub$edu3+ wvs_sub$edu4+ wvs_sub$edu5+ wvs_sub$edu6+ wvs_sub$income2+ wvs_sub$income3+ wvs_sub$income4+ wvs_sub$income5+ wvs_sub$income6+ wvs_sub$income7)$coefficients[2]

conscientiousnesslist[[10]] <- lmcoefs
alphacoefs[1013,] <- psych::alpha(conscientiousness,check.keys = TRUE)$total[1:4]


lmcoefs <- matrix(nrow=10,ncol=3)

for(i in 1:ncol(conscientiousness)){
  lmcoefs[i,1]   <-   lm(zero1(wvs_sub$wvs_lrplacement)~zero1((conscientiousness)[,i])+  wvs_sub$IPIP_open+wvs_sub$IPIP_ext+wvs_sub$IPIP_agre+wvs_sub$IPIP_neu+wvs_sub$gender+ wvs_sub$age+ wvs_sub $age2+  wvs_sub$edu2+ wvs_sub$edu3+ wvs_sub$edu4+ wvs_sub$edu5+ wvs_sub$edu6+ wvs_sub$income2+ wvs_sub$income3+ wvs_sub$income4+ wvs_sub$income5+ wvs_sub$income6+ wvs_sub$income7)$coefficients[2]
  lmcoefs[i,2]   <-   lm(zero1(wvs_sub$wvs_moral)~zero1((conscientiousness)[,i])+  wvs_sub$IPIP_open+wvs_sub$IPIP_ext+wvs_sub$IPIP_agre+wvs_sub$IPIP_neu+wvs_sub$gender+ wvs_sub$age+ wvs_sub $age2+  wvs_sub$edu2+ wvs_sub$edu3+ wvs_sub$edu4+ wvs_sub$edu5+ wvs_sub$edu6+ wvs_sub$income2+ wvs_sub$income3+ wvs_sub$income4+ wvs_sub$income5+ wvs_sub$income6+ wvs_sub$income7)$coefficients[2]
  lmcoefs[i,3]   <-   lm(zero1(wvs_sub$wvs_economicattitudes)~zero1((conscientiousness)[,i])+  wvs_sub$IPIP_open+wvs_sub$IPIP_ext+wvs_sub$IPIP_agre+wvs_sub$IPIP_neu+wvs_sub$gender+ wvs_sub$age+ wvs_sub$age2+  wvs_sub$edu2+ wvs_sub$edu3+ wvs_sub$edu4+ wvs_sub$edu5+ wvs_sub$edu6+ wvs_sub$income2+ wvs_sub$income3+ wvs_sub$income4+ wvs_sub$income5+ wvs_sub$income6+ wvs_sub$income7)$coefficients[2]
}
conscientiousnesslist[[1]] <- lmcoefs

l <- Map(cbind, conscientiousnesslist, indx = seq_len(length(conscientiousnesslist))) 
h <- data.frame(do.call(rbind, l))
head(h )
names(h) <- c("Left-Right","Moral","Economic Ideology","Index")
empties <- data.frame(matrix(NA,nrow = 10,ncol = 4))
colnames(empties) <- colnames(alphacoefs)
alphacoefs <- rbind(empties,alphacoefs)
itemstogether <- unlist(rr)
itemstogether[1023] <- "all"
numall <- unlist(emptylist)
outstanding <- data.frame(h,itemstogether,alphacoefs)
library(reshape2)
forfig <- melt(outstanding,id.vars=c("Index","itemstogether",names(empties)))
forfig$trait <- "Conscientiousness"

